#include<iostream>
#include<algorithm>
using namespace std;
// zdl:: 这道题目气就是一道贪心的题目，可以直接使用sort + 双指针
const int N  = 1e3 + 10;
int a[N];
int n;
using ll = long long;
ll get(int a, int b)
{
    return (a - b) * (a - b);
}
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    sort(a + 1, a + 1 + n);
    ll sum = a[n] * a[n];
    int l = 1, r = n;
    while (l < r)
    {
        sum += get(a[l], a[r--]);
        sum += get(a[l++], a[r]);
    }

    cout << sum << endl;
    return 0;
}